using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Configuration;
using ShoppingCenter.Backend.Api.Model;
using ShoppingCenter.Backend.Api.Params;
using ShoppingCenter.Backend.Api.Repository;
using ShoppingCenter.Backend.Api.Utils;

namespace ShoppingCenter.Backend.Api.Controllers
{
    // [Authorize]
    [ApiController]
    [Route("[controller]")]

    //商品评价控制器
    public class CommentController : ControllerBase
    {
        private IConfiguration _configuration;

        private IRepository<Comment> _commentRepository;

        public CommentController(IConfiguration configuration, IRepository<Comment> commentRepository)
        {
            _configuration = configuration;
            _commentRepository = commentRepository;
        }

        //获取所有评价
        public dynamic Get()
        {
            var currentPage = int.Parse(Request.Query["currentPage"][0]);
            var pageSize = int.Parse(Request.Query["pageSize"][0]);

            // 分页
            var comments = _commentRepository.Table.ToList();
            var comment=comments.Skip((currentPage - 1) * pageSize).Take(pageSize); ;


            return new
            {
                Code = 1000,
                Data = new
                {
                    Data = comment,
                    Pager = new { currentPage, pageSize, totalSize = comments.Count() }
                },
                Msg = "获取所有商品评价成功"
            };
        }
    }
}